<?php

class SViewer
{

    private static $instance = NULL;

    private function __construct ()
    {}

    public static function singleton ()
    {
        if (! isset(static::$instance)) {
            static::$instance = new static();
        }
        return static::$instance;
    }

    public function set ($viewer)
    {
        \Session::set('viewer', '');
        \Session::set('viewer', $viewer);
    }

    public function __get ($key)
    {
        $viewer = \Session::get('viewer', array());
        return array_key_exists($key, $viewer) ? $viewer[$key] : null;
    }

    public function __set ($key, $val)
    {
        $viewer = \Session::get('viewer', array());
        
        if (isset($viewer['_id']))
            unset($viewer['_id']);
        
        $viewer[$key] = $val;
        \Session::set('viewer', $viewer);
    }

    public function get ()
    {
        $viewer = \Session::get('viewer', array());
        return $viewer;
    }

}